package com.example.lanouhn.bantangapp.activities.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lanouhn.bantangapp.R;
import com.example.lanouhn.bantangapp.activities.contants.TogLine;
import com.example.lanouhn.bantangapp.activities.contants.TogSun;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lanouhn on 16/7/19.
 */
public class Adapter_TogSun extends RecyclerView.Adapter<Adapter_TogSun.MyViewHolder> {
    private Context context;
    List<TogSun> list;

    public Adapter_TogSun(Context context, List<TogSun> list) {
        this.context = context;
        this.list = list;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.sun_item,null);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.content.setText(list.get(position).getContent());
        holder.nickname.setText(list.get(position).getNickname());
        holder.likes.setText(list.get(position).getLikes());
        //图片
        Picasso.with(context).load(list.get(position).getMiddle_pic_url()).into(holder.image);
        Picasso.with(context).load(list.get(position).getAvatar()).into(holder.avatar);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private TextView  content;
        private TextView  nickname;
        private TextView  likes;
        private ImageView image;
        private ImageView avatar;

        public MyViewHolder(View itemView) {
            super(itemView);
            content= (TextView) itemView.findViewById(R.id.content);
            avatar= (ImageView) itemView.findViewById(R.id.avatar);
            nickname= (TextView) itemView.findViewById(R.id.nickname);
            likes= (TextView) itemView.findViewById(R.id.likes);
            image= (ImageView) itemView.findViewById(R.id.image);


        }
    }
}
